package com.demo.study.thread;

import org.springframework.scheduling.annotation.Async;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author leiliang
 * @version 1.0
 * @Description
 * @date 2021/1/5 16:10
 */
public class Thread003 implements Callable<String> {

    @Override
    public String call() throws Exception {
        System.out.printf(Thread.currentThread().getName() + "开始异步发送短信");
        Thread.sleep(3000);
        return "异步发送短信";
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //获取异步的返回结果
        FutureTask<String> stringFutureTask = new FutureTask<>(new Thread003());
        new Thread(stringFutureTask).start();
        System.out.printf( "result" + stringFutureTask.get());
    }
}
